package com.tax.infrastructure.extension;

import org.apache.commons.lang3.StringUtils;

/**
 * duandehui
 * BizScenario(业务场景)= biz_id + use_case + scenario ,which can unique identifu a user scenario
 */
public class BizScenario {

    /**
     * default biz
     */
    public static final String DEFAULT_BIZ_ID = "UDBUS";

    /**
     * default business function
     */
    public static final String DEFAULT_USE_CASE = "";

    /**
     * default product code
     */
    public static final String DEFAULT_SCENARIO = "";

    public static final String DOT_SEPARATOR = ".";

    /**
     * bizId is used to identify a business,such as "udiannet" ,it's nullable if there os only one biz
     */
    private String biz = DEFAULT_BIZ_ID;

    /**
     * useCase is used to identify a use case,such as "placeOrder",can not be null
     */
    private String useCase = DEFAULT_USE_CASE;

    /**
     * scenario is used to identify a use case,such as "88vip","normal",can not be null
     */
    private String scenario = DEFAULT_SCENARIO;

    /**
     * for above case ,such as "udiannet.placeOrder.88vip"
     * @return
     */
    public String getUniqueIdentity() {
        String uniqueIdentity = biz;
        if (StringUtils.isNotBlank(useCase)) {
            uniqueIdentity += DOT_SEPARATOR + useCase;
        }
        if (StringUtils.isNotBlank(scenario)) {
            uniqueIdentity += DOT_SEPARATOR + scenario;
        }
        return uniqueIdentity;
    }

    static String getDefaultUniqueIdentity() {
        return DEFAULT_BIZ_ID;
    }

    public static BizScenario valueOf(String bizId, String useCase, String scenario) {
        BizScenario bizScenario = new BizScenario();
        bizScenario.biz = bizId;
        bizScenario.useCase = useCase;
        bizScenario.scenario = scenario;
        return bizScenario;
    }

    public static BizScenario valueOf(String bizId, String scenario) {
        return BizScenario.valueOf(bizId, DEFAULT_USE_CASE, scenario);
    }

    public static BizScenario valueOf(String useCase) {
        return BizScenario.valueOf(DEFAULT_BIZ_ID, useCase, DEFAULT_SCENARIO);
    }

    public static BizScenario newDefault() {
        return BizScenario.valueOf(DEFAULT_BIZ_ID, DEFAULT_USE_CASE, DEFAULT_SCENARIO);
    }
}
